home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJGOS106.ARJ / WILD.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  2KB  |  69 lines

  1. /* This is file WILD.C */
  2. /*
  3. ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. int wild(char *pattern, char *string)
  16. {
  17.   int nlit;
  18.   while (*pattern)
  19.   {
  20.     switch (*pattern)
  21.     {
  22.       case '*':
  23.         pattern++;
  24.         if (*pattern == 0)
  25.           return 1;
  26.         nlit=0;
  27.         while ((pattern[nlit] != 0)
  28.             && (pattern[nlit] != '*')
  29.             && (pattern[nlit] != '?') )
  30.           nlit++;
  31.         while (1)
  32.         {
  33.           if (strncmp(string, pattern, nlit) == 0)
  34.             break;
  35.           string++;
  36.           if (*string == 0)
  37.             return 0;
  38.         }
  39.         break;
  40.       case '?':
  41.         if (*string == 0)
  42.           return 0;
  43.         pattern++;
  44.         string++;
  45.         break;
  46.       default:
  47.         if (*pattern != *string)
  48.           return 0;
  49.         pattern++;
  50.         string++;
  51.         break;
  52.     }
  53.   }
  54.   if (*string)
  55.     return 0;
  56.   return 1;
  57. }
  58.  
  59. #ifdef DEBUG
  60. main(int argc, char **argv)
  61. {
  62.   int i;
  63.   if (argc < 3)
  64.     return 1;
  65.   for (i=2; argv[i]; i++)
  66.     printf("%s %s %d\n", argv[1], argv[i], wild(argv[1], argv[i]));
  67.   return 0;
  68. }
  69. #endif